# -*- coding: utf-8 -*-

"""
 (c) 2023 - Copyright CTyunOS Inc

 Authors:
   youyifeng <youyf2@chinatelecom.cn>

"""

from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import PickleType
from sqlalchemy import Text

from .base import DBModel


class SA(DBModel):
    __tablename__ = 'OpenEulerSA'

    id = Column('id', Integer, primary_key=True)
    affectedComponent = Column('affectedComponent', Text)
    affectedProduct = Column('affectedProduct', Text)
    announcementTime = Column('announcementTime', Text)
    cveId = Column('cveId', Text)
    description = Column('description', Text)
    introduction = Column('introduction', Text)
    packageName = Column('packageName', Text)
    referenceDocuments = Column('referenceDocuments', Text)
    revisionHistory = Column('revisionHistory', Text)
    securityNoticeNo = Column('securityNoticeNo', Text)
    subject = Column('subject', Text)
    summary = Column('summary', Text)
    type = Column('type', Text)
    notice_type = Column('notice_type', Text)
    updateTime = Column('updateTime', Text)
    cvrf = Column('cvrf', Text)

    packageHelperList = Column('packageHelperList', PickleType)
    packageHotpatchList = Column('packageHotpatchList', PickleType)
    packageList = Column('packageList', PickleType)
    referenceList = Column('referenceList', PickleType)
    cveList = Column('cveList', PickleType)

    COLUMN = [
        "id",
        "affectedComponent",
        "affectedProduct",
        "announcementTime",
        "cveId",
        "description",
        "introduction",
        "packageName",
        "referenceDocuments",
        "revisionHistory",
        "securityNoticeNo",
        "subject",
        "summary",
        "type",
        "notice_type",
        "updateTime",
        "cvrf",
        "packageHelperList",
        "packageHotpatchList",
        "packageList",
        "referenceList",
        "cveList",
    ]

    @staticmethod
    def pretty_output_title():
        print("%-20s %-30s %-10s %-20s" % ("securityNoticeID", "AffectedComponent", "CVEID", "UpdateTime"))

    def pretty_output(self):
        print("%-20s  %-20s %-30s %-10s" % (
            self.securityNoticeNo,
            self.updateTime,
            self.affectedComponent.replace('\n',' '),
            self.cveId.replace('\n',' '),
        ))

    def simple_output(self):
        print("""SecurityNoticeNo: %s
AffectedComponent: %s
CVEID: %s
UpdateTime: %s
Link: https://www.openeuler.org/zh/security/safety-bulletin/detail/?id=%s
""" % (
            self.securityNoticeNo,
            self.affectedComponent.replace('\n',' '),
            self.cveId.replace('\n',' '),
            self.updateTime,
            self.securityNoticeNo.replace('\n',' '),
        ))
